package com.ruoyi.web.controller.front;

import java.util.List;

import com.ruoyi.front.domain.CommonProblem;
import com.ruoyi.front.domain.ContractTemplate;
import com.ruoyi.front.service.ICommonProblemService;
import com.ruoyi.front.service.IContractTemplateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.front.domain.ContractTemplateProblem;
import com.ruoyi.front.service.IContractTemplateProblemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同模板、常见问题关系Controller
 * 
 * @author ruoyi
 * @date 2020-11-07
 */
@Controller
@RequestMapping("/front/templateProblem")
public class ContractTemplateProblemController extends BaseController
{
    private String prefix = "front/templateProblem";

    @Autowired
    private IContractTemplateProblemService contractTemplateProblemService;
    @Autowired
    private IContractTemplateService contractTemplateService;
    @Autowired
    private ICommonProblemService commonProblemService;

    @RequiresPermissions("front:templateProblem:view")
    @GetMapping()
    public String templateProblem()
    {
        return prefix + "/templateProblem";
    }

    /**
     * 查询合同模板、常见问题关系列表
     */
    @RequiresPermissions("front:templateProblem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContractTemplateProblem contractTemplateProblem)
    {
        startPage();
        List<ContractTemplateProblem> list = contractTemplateProblemService.selectContractTemplateProblemList(contractTemplateProblem);
        return getDataTable(list);
    }

    /**
     * 导出合同模板、常见问题关系列表
     */
    @RequiresPermissions("front:templateProblem:export")
    @Log(title = "合同模板、常见问题关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ContractTemplateProblem contractTemplateProblem)
    {
        List<ContractTemplateProblem> list = contractTemplateProblemService.selectContractTemplateProblemList(contractTemplateProblem);
        ExcelUtil<ContractTemplateProblem> util = new ExcelUtil<ContractTemplateProblem>(ContractTemplateProblem.class);
        return util.exportExcel(list, "templateProblem");
    }

    /**
     * 新增合同模板、常见问题关系
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("contractTemplateList",contractTemplateService.selectContractTemplateList(new ContractTemplate()));
        mmap.put("commonProblemList",commonProblemService.selectCommonProblemList(new CommonProblem()));
        return prefix + "/add";
    }

    /**
     * 新增保存合同模板、常见问题关系
     */
    @RequiresPermissions("front:templateProblem:add")
    @Log(title = "合同模板、常见问题关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContractTemplateProblem contractTemplateProblem)
    {
        return toAjax(contractTemplateProblemService.insertContractTemplateProblem(contractTemplateProblem));
    }

    /**
     * 修改合同模板、常见问题关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ContractTemplateProblem contractTemplateProblem = contractTemplateProblemService.selectContractTemplateProblemById(id);
        mmap.put("contractTemplateProblem", contractTemplateProblem);
        mmap.put("contractTemplateList",contractTemplateService.selectContractTemplateList(new ContractTemplate()));
        mmap.put("commonProblemList",commonProblemService.selectCommonProblemList(new CommonProblem()));
        return prefix + "/edit";
    }

    /**
     * 修改保存合同模板、常见问题关系
     */
    @RequiresPermissions("front:templateProblem:edit")
    @Log(title = "合同模板、常见问题关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContractTemplateProblem contractTemplateProblem)
    {
        return toAjax(contractTemplateProblemService.updateContractTemplateProblem(contractTemplateProblem));
    }

    /**
     * 删除合同模板、常见问题关系
     */
    @RequiresPermissions("front:templateProblem:remove")
    @Log(title = "合同模板、常见问题关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contractTemplateProblemService.deleteContractTemplateProblemByIds(ids));
    }
}
